package sources;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

/**
 * A class that runs the Error GUI and behind the scene code.
 *
 * @author Alana Meditz
 * @author Ty Yago
 * @author Katherine Kishaba
 * @author Jimmy CUmming
 * 
 */

public class ErrorFrame extends JFrame {
	private static final int WIDTH = 300;
	private static final int HEIGHT = 200;
	
	private JButton okayB;
	private JLabel messageL;
	private OkayButtonHandler okayBH;
	
	/**
	 * ErrorFrame constructor.
	 * Creates the GUI allowing users to add event components to the given ICalendar object. 
	 * @param iCal The ICalendar to which event components will be added.
	 */
	public ErrorFrame(String message) {
		setUpFrame();
		
		messageL = new JLabel(message);
		
		instantiateButtons();
		
		setUpPane();
	}
	
	/**
	 * Helper function used by the constructor to declare properties of this AddEventFrame
	 */
	private void setUpFrame() {
		setTitle("Error");
		setSize(WIDTH, HEIGHT);
		setVisible(true);
	}
	
	/**
	 * Helper function used by constructor to create buttons and implement their event handlers.
	 */
	private void instantiateButtons() {
		okayB = new JButton("Okay");
		okayBH = new OkayButtonHandler();
		okayB.addActionListener(okayBH);
	}
	
	/**
	 * Helper function used by constructor to declare pane properties and add Frame elements to the
	 * ContentPane of this frame for display.
	 */
	private void setUpPane() {
		Container pane = getContentPane();
		pane.setLayout(new GridLayout(2, 1));
		
		// Add items to pane
		pane.add(messageL);
		pane.add(okayB);
	}
	
	/**
	 * Event handler for the "Okay" button.
	 */
	private class OkayButtonHandler implements ActionListener {
		public void actionPerformed(ActionEvent e) {	
			setVisible(false);
		}
	}
}